package com.zzyl.service.impl;

import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    /**
     * 将传入的床位信息添加到数据库
     * @param bedDto 床位信息
     * @return
     */
    @Override
    public void addBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto,bed);
        //补齐数据
        bed.setUpdateBy(bed.getCreateBy());
        bed.setBedStatus(0);
        bedMapper.insert(bed);
    }

    /**
     * 根据床位id查询床位信息
     * @param id 床位id
     * @return
     */
    @Override
    public BedVo getBed(Long id) {
        Bed bed = bedMapper.selectById(id);
        BedVo bedVo = new BedVo();
        BeanUtils.copyProperties(bed,bedVo);
        return bedVo;
    }

    /**
     * 根据id更新床位信息
     * @param bedDto 床位
     */
    @Override
    public void updateBed(BedDto bedDto) {
        Bed bed = new Bed();
        bed.setUpdateBy(1L);
        BeanUtils.copyProperties(bedDto,bed);
        bedMapper.updateById(bed);
    }

    /**
     * 根据id删除床位
     * @param id 床位id
     */
    @Override
    public void deleteBed(Long id) {
        bedMapper.deleteBed(id);
    }

}

